# class LoginAction(object):#用户选择注册登录
#     def __init__(self,ID,Pwd):
#         self.ID=ID
#         self.Pwd=Pwd
#     def user_register(self):#注册
#         pass
#     def user_login(self):#登录
#         pass
#     def user_out(self):#退出
#         pass
# class InformationAction(object):#个人信息中心
#     def add_Information(self):#增加信息
#         pass
#     def update_Information(self):#修改信息
#         pass
#     def get_Information(self):#删除信息
#         pass
# class FunctionSelct(LoginAction,InformationAction):#买家进入
#     def find_AllProduct(self):#浏览所有商品
#         pass
#     def find_ShopCar(self):#查看购物车
#         pass
#     def find_OrderList(self):#查看订单
#         pass
import xlrd
import xlwt
from xlutils.copy import copy
print('''********************
  欢迎进入电商平台
''')
def Login_Action():
    print('''
我们为您提供以下服务

1:浏览商品
2:登录
3:注册
4:我要开店
5:退出
''')
    chose=input('请输入你的选择：').strip()
    return chose
class Excel(object):
    def __init__(self,path):
        self.path=path
    def add_data(self,slist):
            add_wt=xlrd.open_workbook(self.path)
            row=add_wt.sheets()[0].nrows
            new_add_wt=copy(add_wt)
            sheet=new_add_wt.get_sheet(0)
            i=0
            for j in slist:
                sheet.write(row,i,j)
                i+=1
            new_add_wt.save(self.path)
class LoginAction(object):#用户选择注册登录
    # def __init__(self,choseuser):
    #     self.choseuser=choseuser
    def user_register(self,role):#注册
        flog=True
        while flog:
            self.role=role
            self.User_ID=input('请设置你的注册ID:').strip()
            wb = xlrd.open_workbook('D:\\txtpython\\users.xls')
            sheet = wb.sheet_by_name('用户账号密码')
            msy = [] 
            msl=[]
            for rownum in range(sheet.nrows):
                msg = []
                for colnum in range(sheet.ncols):
                    msg.append(str(sheet.cell(rownum,colnum).value))
                msy.append(msg)
            for i in msy:
                msl.append(i[0])
            if self.User_ID not in msl:
                self.User_Pwd=input('请设置你的登录密码:').strip()
                user_register_list=[self.User_ID,self.User_Pwd,self.role]       
                print('注册成功',user_register_list)
                flog=False
                return user_register_list
            else:
                print('已存在,重新设置')
                pass
    def user_out(self):#退出
        print('欢迎下次光临')
class InformationAction(object):#个人信息中心
    def get_Information(self,bookname,sheetname,ID):#查看所有信息
    #打开Excel文件
        wb = xlrd.open_workbook(bookname)
        sheet = wb.sheet_by_name(sheetname)
        #for rownum in range(sheet.nrows):
            # print(sheet.row_values(rownum))
        for rownum in range(sheet.nrows):
            msg = []
            for colnum in range(sheet.ncols):
                msg.append(str(sheet.cell(rownum,colnum).value))
            if ID==msg[0]:
                print(msg)
    def add_Information(self):#增加信息
        self.user_addname=input('收货人姓名：')
        self.user_addtel=input('收货人联系方式：')
        self.user_address=input('收货人地址：')
        user_id=login.Login_ID()
        list_add=[user_id,self.user_addname,self.user_addtel,self.user_address]
        excel=Excel('D:\\txtpython\\userinfo.xls')
        excel.add_data(list_add)
        print(list_add)
    def update_Information(self,ID):#修改信息
        wb = xlrd.open_workbook('D:\\txtpython\\userinfo.xls')
        sheet = wb.sheet_by_name('用户信息')
        msy=[]
        msm=[]
        #for rownum in range(sheet.nrows):
            # print(sheet.row_values(rownum))
        for rownum in range(sheet.nrows):
            msg = []
            for colnum in range(sheet.ncols):
                msg.append(str(sheet.cell(rownum,colnum).value))
            msy.append(msg)
        for i in msy:
            if i[0]==ID:
                msm.append(i)
        print(msm)
        for i,j in enumerate(msm,1):
            print(i,j)
        chose_update=input('请输入你需要修改的：').strip()
        chose_update=int(chose_update)-1
        msm_1=msm[chose_update][1:-1]
        print(msm_1)
        for i,j in enumerate(msm_1,1):
            print(i,j)











    def update_pwd(self,pwd):#修改密码
        wb = xlrd.open_workbook('D:\\txtpython\\users.xls')
        sheet = wb.sheet_by_name('用户账号密码')
        msy = []
        msm=[] 
        for rownum in range(sheet.nrows):
            msg = []
            for colnum in range(sheet.ncols):
                msg.append(str(sheet.cell(rownum,colnum).value))
            msy.append(msg)
        print(msy)
        ID=Login_ID
        num=0
        for i in msy:
            msm.append(i[0])
        print(msm)
        num=msm.index(ID)
        new_wb = copy(wb)  # 将原有的Excel，拷贝一个新的副本
        new_sheet = new_wb.get_sheet(0) # 重新在新的Excel中获取sheet页
        new_sheet.write(num,1,pwd)
        new_wb.save('users.xls')
        print('修改成功')        
    def del_Information(self):#删除信息
        pass
class FunctionSelct(LoginAction,InformationAction):#买家进入
    def find_AllProduct(self):#浏览所有商品
        pass
    def find_ShopCar(self):#查看购物车
        pass
    def find_OrderList(self):#查看订单
        pass
class ProductUser(LoginAction):
    pass
class Login(object):
    def __init__(self,login_ID,login_Pwd,role):
        self.login_ID=login_ID
        self.login_Pwd=login_Pwd
        self.role=role
    def __str__(self):
        return '登陆成功'
    def Login_ID(self):
        return self.login_ID
chose=Login_Action()
if chose=='1':
    pass
if chose=='2':
    chose_user=input('1:商家登录    2:用户登录').strip()
    Login_ID=input('请输入你的ID:')
    Login_Pwd=input('请输入你的登录密码:')
    list_login=[Login_ID,Login_Pwd]
    if chose_user=='1':
        #判断是否在表格内
        wb = xlrd.open_workbook('D:\\txtpython\\users.xls')
        sheet = wb.sheet_by_name('用户账号密码')
        msy = [] 
        msl=[]
        for rownum in range(sheet.nrows):
            msg = []
            for colnum in range(sheet.ncols):
                msg.append(str(sheet.cell(rownum,colnum).value))
            msy.append(msg)
        print(msy)
        login=Login(Login_ID,Login_Pwd,'0')
        login_list=[Login_ID,Login_Pwd,'0']
        if login_list not in msy:
            print('账号密码错误或者未注册')
        else:
            print(login)
            print('1:商品管理    2:订单处理')
            chose_produce=input('选择操作：')
            if chose_produce=='1':
                pass
            if chose_produce=='2':
                pass
    elif chose_user=='2':
        wb = xlrd.open_workbook('D:\\txtpython\\users.xls')
        sheet = wb.sheet_by_name('用户账号密码')
        msy = [] 
        msl=[]
        for rownum in range(sheet.nrows):
            msg = []
            for colnum in range(sheet.ncols):
                msg.append(str(sheet.cell(rownum,colnum).value))
            msy.append(msg)
        print(msy)
        login=Login(Login_ID,Login_Pwd,'1')
        login_list=[Login_ID,Login_Pwd,'1']
        if login_list not in msy:
            print('账号密码错误或者未注册')
        else:
            print(login)
            #判断是否在用户的表格内
            print('''
            亲爱的用户欢迎你：
            1.浏览商品
            2.我的购物车
            3.我的订单
            4.我的信息
            5.退出登录''')
            chose_infor=input('请选择:').strip()
            if chose_infor=='1':
                pass
            if chose_infor=='2':
                pass
            if chose_infor=='3':
                pass
            if chose_infor=='4':
                list_infor=['个人所有信息','增加','修改','删除','修改我的密码']
                for i,j in enumerate(list_infor,1):
                    print(i,j)
                chose_infor=input('请输入你的选择编号：')
                if chose_infor=='1':#查看所有
                    ID=Login_ID
                    infor=InformationAction()
                    infor.get_Information('D:\\txtpython\\userinfo.xls','用户信息',ID)
                if chose_infor=='2':#增加
                    infor=InformationAction()
                    infor.add_Information()
                if chose_infor=='3':#修改
                    ID=Login_ID
                    infor=InformationAction()
                    infor.update_Information(ID)
                if chose_infor=='4':#删除
                    pass
                if chose_infor=='5':#修改我的密码
                    infor=InformationAction()
                    new_pwd=input('请输入你的新密码：')
                    infor.update_pwd(new_pwd)           
            if chose=='5':
                pass
if chose=='3':
    l=LoginAction()
    role='1'
    user_register_list=l.user_register(role)
    excel=Excel('D:\\txtpython\\users.xls')
    excel.add_data(user_register_list)
if chose=='4':
    l=LoginAction()
    role='0'
    user_register_list=l.user_register(role)
    excel=Excel('D:\\txtpython\\users.xls')
    excel.add_data(user_register_list)
if chose=='5':
    l.user_out()    